<template>
	<view @touchmove.stop.prevent="moveHandle">
		<view class="detail-opelist" v-if="showStatus">
			<view class="mask-show" @tap.stop="saveShowStatus(false)"></view>
			<view class="opelist-body">
				<view class="guanli flex align-center flex-nowrap">
					<view class="gl-title">管理</view>
					<view class="gl-desc">发布的信息内容管理</view>
				</view>
				<view class="scroll">
					<scroll-view class="scroll-view" scroll-x="true" :enable-flex="true"> 
						<view v-for="(item,index) in scrollOneCheck" :key="index" class="item-parent" @tap="clickBtn(index,'scrollOne')"
						 v-if="item.is_me == 0 || item.is_me == is_me || (item.is_super_admin && is_super_admin == 1)" >
							<view class=" item-parent-up flex align-center justify-center">
								<text class="iconfont" :class="item.icon" :style="{'color':item.color?item.color:''}"></text>
							</view>
							<view class="item-parent-title " >
								{{item.title}}
							</view>
						</view>
						
					</scroll-view> 
				</view>
				<view class="scroll"> 
					<scroll-view class="scroll-view scroll-view2" scroll-x="true">
						<view v-for="(item,index) in scrollTwoCheck" :key="index" class="item-parent" @tap="clickBtn(index,'scrollTwo')"
						v-if="item.is_me == 0 || item.is_me == is_me "
						>
							<view class=" item-parent-up flex align-center justify-center">
								<text class="iconfont" :class="item.icon"></text>
							</view>
							<view class="item-parent-title ">
								{{item.title}}
							</view>
						</view> 
						
					</scroll-view> 
				</view>
				
			</view>
			<view class="cancel-btn" @tap="saveShowStatus(false)">取消</view>    
		</view>
	</view>
</template> 

<script>
	export default {
		props:{
			showPageIndex:{
				type:Boolean,
				default:true
			}
		},
		data() {
			return {
				callback:null,
				showStatus:false,
				info:{},
				is_me:-99,
				is_super_admin:0,
				scrollOneCheck:[],
				scrollTwoCheck:[],
				scrollOne:[
					{type:'index',title:'首页',icon:'icon-shouye',color:'#26C390',is_me:0},
					{type:'edit',title:'编辑',icon:'icon-bianji',color:'#E39342',is_me:0},
					{type:'join',title:'我的记录',icon:'icon-jilu',color:'#66AA7D',is_me:0},
					{type:'join',title:'参加记录',icon:'icon-jilu',color:'#66AA7D',is_me:-1},
					{type:'fenxi',title:'统计分析',icon:'icon-tongji',color:'#1296DB',is_me:0,is_super_admin:0},
					{type:'buka',title:'补卡',icon:'icon-buka',color:'#66AA7D',is_me:0},
					{type:'excel',title:'导出数据',icon:'icon-daochu',color:'#26C390',is_me:0,is_super_admin:0},
				],
				scrollTwo:[
					{type:'copy',title:'复制创建',icon:'icon-fuzhi',is_me:0},
					{type:'copy',title:'套用模板',icon:'icon-fuzhi',is_me:0},
					{type:'create',title:'空白创建',icon:'icon-jiahao',is_me:0},
					{type:'start',title:'设为开始',icon:'icon-kaishi',is_me:0},
					{type:'end',title:'设为结束',icon:'icon-tingzhi',is_me:0},
					/* {type:'notice',title:'设置提醒',icon:'icon-tixing',is_me:1}, */
					{type:'delete',title:'删除',icon:'icon-shanchu',is_me:0},
				]
			}
		},
		methods: {
			clickBtn(index,dataType)
			{
				var that = this;
				var list = [];
				switch(dataType)
				{
					case 'scrollOne':
						list = that.scrollOneCheck;
						break;
					case 'scrollTwo':
						list = that.scrollTwoCheck;
						break;	
				}
				var selInfo = list[index]?list[index]:'';
				var info = that.info;
				if(!selInfo)
				{
					that.$api.msg('获取数据失败');return ;
				}
				switch(selInfo.type)
				{
					case 'index':
						that.$api.navigateTo('/pages/index/index');
						break;
					case 'edit':
						if(info.join_count && info.join_count > 0)
						{
							/* that.$api.msg('已有'+info.join_count+'人参加，无法修改');
							return ; */
						}
						that.editInfo();
						break;	
					case 'join':
						that.$api.navigateTo('/pages/form/statistics/my-join?s_id='+that.info.s_id);
						break;
					case 'notice':
						that.$api.navigateTo('/pages/form/statistics/join-notice-set?s_id='+that.info.s_id);
						break;	
					case 'buka':
						if(typeof that.callback == 'function')
						{
							that.callback({
								opeType:'buka'
							});
						}
						break;
					case 'excel':
						that.excelInfo();
						break;	
					case 'fenxi':
						that.showJoinTable();
						break;
					case 'copy':
						that.editInfo(true);
						break;
					case 'create':
						that.createInfo();
						break;
					case 'start':
						var text = '确认设置为开始吗？';
						that.$api.showModal(text,'',function(res){
							if(res == 'yes')
							{
								that.setInfoTime();
							}
						});
						break;
					case 'end':
						var text = '确认设置为已结束吗？';
						that.$api.showModal(text,'',function(res){
							if(res == 'yes')
							{
								that.setInfoTime();
							}
						});
						break;
					case 'delete':
						that.$api.showModal('删除后不可恢复，确认操作','',function(res){
							if(res == 'yes')
							{
								that.delInfo();
							}
						})
						break;
				}
				that.saveShowStatus(false);
			},
			delInfo(){
				var that = this;
				that.$api.loadingMsg('正在删除');
				that.$http.post('statistics/delInfo',{
					s_id:that.info.s_id
				}).then(res=>{
					that.$api.msg(res.msg);
					if(res.code == 1)
					{
						if(typeof that.callback == 'function')
						{
							res.opeType = 'delete';
							that.callback(res);
						}
					}
				});
			},
			
			setInfoTime(){
				var that = this;
				that.$api.loadingMsg('正在设置');
				that.$http.post('statistics/setInfoTime',{
					s_id:that.info.s_id
				}).then(res=>{
					that.$api.msg(res.msg);
					if(res.code == 1)
					{
						if(typeof that.callback == 'function')
						{
							res.opeType = 'setTime';
							that.callback(res);
						}
					}
				});
				
			},
			createInfo()
			{
				var url = '';
				switch(this.info.type)
				{
					case 1:
						var url = '/pages/form/statistics/add';
						break;
					case 2:
						var url = '/pages/form/daka/add';
						break;
				}
				this.$api.navigateTo(url);
			},
			copyInfo(){
				var s_id = this.info.s_id;
				if(s_id < 1)
				{
					this.$api.msg('未获取到复制信息');
					return ;
				}
				this.$api.navigateTo('/pages/form/daka/edit?copy=1&s_id='+s_id);
			},
			showJoinTable(){
				if(this.info.is_me != 1 && this.is_super_admin != 1)
				{
					this.$api.msg('只有管理员才能查看');
					return ;
				}
				this.$api.navigateTo('/pages/form/statistics/join-table?s_id='+this.info.s_id);
			},
			excelInfo(){
				if(this.info.is_me != 1 && this.is_super_admin != 1)
				{
					this.$api.msg('只有管理员才能导出数据');
					return ;
				}
				this.$api.navigateTo('/pages/form/statistics/list-export?s_id='+ this.info.s_id);
			},
			editInfo(isCopy){
				var s_id = this.info.s_id;
				if(s_id < 1)
				{
					this.$api.msg('未获取到数据信息');
					return ;
				}
				var url = '';
				switch(this.info.type)
				{
					case 1:
						var url = '/pages/form/statistics/edit?s_id='+this.info.s_id;
						break;
					case 2:
						var url = '/pages/form/daka/edit?s_id='+this.info.s_id;
						break;
				}
				if(isCopy)
				{
					url = url + '&copy=1';
				}
				this.$api.navigateTo(url);
			},
			saveShowStatus(status)
			{
				this.showStatus = status;
			},
			initData(info,callback)
			{
				let scrollOne = JSON.parse(JSON.stringify(this.scrollOne));
				for(var i=0;i<scrollOne.length;i++)
				{
					if(this.showPageIndex == false && scrollOne[i].type == 'index')
					{
						scrollOne.splice(i,1);
						continue;
					}
					if(!info.can_buka && scrollOne[i].type == 'buka')
					{
						scrollOne.splice(i,1);
						continue;
					}
				}
				this.scrollOneCheck = scrollOne;
				let scrollTwo = JSON.parse(JSON.stringify(this.scrollTwo));
				for(var i=0;i<scrollTwo.length;i++)
				{
					
					if(info.time_status)
					{
						if(info.time_status == 1 && scrollTwo[i].type == 'start')
						{
							scrollTwo.splice(i,1);continue;
						}else if(info.time_status != 1 && scrollTwo[i].type == 'end')
						{
							scrollTwo.splice(i,1);continue;
						}
					}
				}
				this.scrollTwoCheck = scrollTwo; 
				if(info.is_me)
				{
					this.is_me = info.is_me;
				}
				
				if(info.is_super_admin)
				{
					this.is_super_admin = info.is_super_admin;
				}
				if(callback)
				{
					this.callback = callback;
				}
				this.info = info;
				this.showStatus = true;
			}
		}
	}
</script>

<style lang="scss">
.detail-opelist{
	width: 100%;
	position: relative;
	.cancel-btn{
		position: fixed;
		bottom: 0;
		z-index: 103;
		background: #ffffff;
		width: 100%;
		height: 110rpx;
		text-align: center;
		line-height: 90rpx;
		font-size: 28rpx;
		color: #666666;
	}
	.opelist-body{
		padding:0 20rpx;
		background-color: #EFEFEF;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		z-index: 102;
		height: 650rpx;
		.guanli{
			height: 100rpx;
			line-height: 100rpx;
			
			font-size: 26rpx;
			border-bottom: 2rpx solid #E1E1E1;
			.gl-title{
				width: 470rpx;
				font-weight: bold;
			}
			.gl-desc{
				overflow: hidden;
				height: 100%;
				color: #999999;
				text-align: right;
				font-size: 24rpx;
			}
		}
		
		.scroll{
			.scroll-view{
				white-space: nowrap;
				padding: 30rpx 0 10rpx 0;
				border-bottom: 2rpx solid #E1E1E1;
				height: 220rpx;
				.item-parent{
					width: 128rpx;
					display: inline-block;
					position: relative;
					vertical-align:top;
				}
				.item-parent-up{
					width: 100rpx;
					height: 100rpx;
					border-radius: 20rpx;
					background-color: #ffffff;
					.iconfont{
						font-size: 50rpx;
						color:$uni-btn-color;
					}
				}
				.item-parent-title{
					width: 100rpx;
					height: 60rpx;
					white-space: normal;
					overflow: hidden;
					color: #999999;
					font-size: 22rpx; 
					text-align: center;
					overflow: hidden;
					margin-top: 10rpx;
					line-height: 30rpx;
				}
			}
			.scroll-view2{
				border-bottom: none;
			}
			
		}
	}
}
</style>
